package user

import (
	"dy/pkg/code"
	"dy/pkg/jwt"
	"github.com/gin-gonic/gin"
)

func (u *ControllerUser) UserInfo(ctx *gin.Context) {
	type param struct {
		UserId int    `form:"user_id" json:"user_id" binding:"required"`
		Token  string `form:"token" json:"token" binding:"required"`
	}
	var request param
	err := ctx.Bind(&request)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	userId, err := jwt.ParseToken(request.Token)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}
	user, err := u.srv.User().GetInfo(ctx, request.UserId, userId)
	if err != nil {
		code.ErrReturn(ctx, err.Error())
		return
	}

	ctx.JSON(200, gin.H{
		"status_code": 0,
		"status_msg":  "success",
		"user":        user,
	})
	return
}
